﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DocumentManagement.Models;
using System.ComponentModel;
using System.Windows;
using System.Windows.Data;

namespace DocumentManagement.ViewsModels
{
    public class ReportDocumentINFromDivisionViewsModel : ViewsModelBase
    {
        public QSHCEntities1 _entityModels;
        public QSHCEntities1 EntityModels
        {
            get { return _entityModels; }
            set
            {
                if (_entityModels != value)
                {
                    _entityModels = value;
                    OnPropertyChanged("EntityModels");
                }
            }
        }

        private Receive _myReceive;
        public Receive MyReceive
        {
            get { return _myReceive; }
            set
            {
                if (_myReceive != value)
                {
                    _myReceive = value;
                    OnPropertyChanged("MyReceive");

                    //if (MyReceive != null)
                    //    MyReceiveICV = CollectionViewSource.GetDefaultView(EntityModels.Receives.Where(p => p.Active == true).ToList());
                }
            }
        }
     


        public ICollectionView _myReceiveICV;
        public ICollectionView MyReceiveICV
        {
            get { return _myReceiveICV; }
            set
            {
                if (_myReceiveICV != value)
                {
                    _myReceiveICV = value;
                    OnPropertyChanged("MyReceiveICV");
                }
            }
        }

        private int _myText1;
        public int MyText1
        {
            get { return _myText1; }
            set
            {
                if (_myText1 != value)
                {
                    _myText1 = value;
                    OnPropertyChanged("MyText1");
                }
            }
        }
        private int _myText2;
        public int MyText2
        {
            get { return _myText2; }
            set
            {
                if (_myText2 != value)
                {
                    _myText2 = value;
                    OnPropertyChanged("MyText2");
                }
            }
        }
        private int _myText3;
        public int MyText3
        {
            get { return _myText3; }
            set
            {
                if (_myText3 != value)
                {
                    _myText3 = value;
                    OnPropertyChanged("MyText3");
                }
            }
        }
        private int _myTextDivionID;
        public int MyTextDivionID
        {
            get { return _myTextDivionID; }
            set
            {
                if (_myTextDivionID != value)
                {
                    _myTextDivionID = value;
                    OnPropertyChanged("MyTextDivionID");
                }
            }
        }

        public ReportDocumentINFromDivisionViewsModel()
        {
            if (!DesignerProperties.GetIsInDesignMode(new DependencyObject()))
            {
                EntityModels = new QSHCEntities1();

            }
        }

        public void CheckDivisionID()
        {
            //MessageBox.Show(MyTextDivionID.ToString());
            MyReceiveICV = CollectionViewSource.GetDefaultView(EntityModels.Receives.Where(p => p.FormDivisionID == MyTextDivionID).Where(p => p.Active==true).ToList()); //.Where(p => p.Active == true)
            MyText1 = EntityModels.Receives.Where(p => p.FormDivisionID == MyTextDivionID).Where(p => p.Active == true).Count();//EntityModels.Receives.Count(p => p.Active == true);
            MyText2 = EntityModels.Receives.Where(p => p.FormDivisionID == MyTextDivionID).Where(p => p.Type == 1).Where(p => p.Active==true).Count();//EntityModels.Receives.Count(p => p.Status == 1);
            MyText3 = EntityModels.Receives.Where(p => p.FormDivisionID == MyTextDivionID).Where(p => p.Type == 2).Where(p => p.Active==true).Count();//EntityModels.Receives.Count(p => p.Status == 2);

        }
    }

}
